﻿namespace TestTool.GUI
{
    using System;
    using System.ComponentModel;
    using System.Drawing;
    using System.Windows.Forms;

    public class IPInput : Form
    {
        private Button btnCancel;
        private Button btnOK;
        private IContainer components;
        private Label lblIPAddress;
        private Label lblprefix;
        private Label lblToken;
        private TextBox tbIpAddress;
        private TextBox tbPrefix;
        private TextBox tbToken;

        public IPInput()
        {
            this.InitializeComponent();
        }

        private void btnOK_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(this.tbToken.Text))
            {
                this.ShowPrompt("Please enter network interface token", "Token is empty");
                this.tbToken.Focus();
            }
            else if (string.IsNullOrEmpty(this.tbIpAddress.Text))
            {
                this.ShowPrompt("Please enter device IP address", "IP Address is empty");
                this.tbIpAddress.Focus();
            }
            else
            {
                int num;
                if (!int.TryParse(this.tbPrefix.Text, out num))
                {
                    this.ShowPrompt("Prefix should be integer", "Prefix is incorrect");
                    this.tbPrefix.Focus();
                }
                else
                {
                    base.DialogResult = DialogResult.OK;
                }
            }
        }

        protected override void Dispose(bool disposing)
        {
            if (disposing && (this.components != null))
            {
                this.components.Dispose();
            }
            base.Dispose(disposing);
        }

        private void InitializeComponent()
        {
            ComponentResourceManager manager = new ComponentResourceManager(typeof(IPInput));
            this.lblToken = new Label();
            this.tbToken = new TextBox();
            this.tbIpAddress = new TextBox();
            this.lblIPAddress = new Label();
            this.btnOK = new Button();
            this.btnCancel = new Button();
            this.lblprefix = new Label();
            this.tbPrefix = new TextBox();
            base.SuspendLayout();
            this.lblToken.AutoSize = true;
            this.lblToken.Location = new Point(12, 0x15);
            this.lblToken.Name = "lblToken";
            this.lblToken.Size = new Size(0x29, 13);
            this.lblToken.TabIndex = 0;
            this.lblToken.Text = "Token:";
            this.tbToken.Location = new Point(0x66, 0x12);
            this.tbToken.Name = "tbToken";
            this.tbToken.Size = new Size(0x8d, 20);
            this.tbToken.TabIndex = 1;
            this.tbIpAddress.Location = new Point(0x66, 0x2d);
            this.tbIpAddress.Name = "tbIpAddress";
            this.tbIpAddress.Size = new Size(0x8d, 20);
            this.tbIpAddress.TabIndex = 2;
            this.lblIPAddress.AutoSize = true;
            this.lblIPAddress.Location = new Point(12, 0x30);
            this.lblIPAddress.Name = "lblIPAddress";
            this.lblIPAddress.Size = new Size(0x3d, 13);
            this.lblIPAddress.TabIndex = 3;
            this.lblIPAddress.Text = "IP Address:";
            this.btnOK.Location = new Point(0x34, 0x6b);
            this.btnOK.Name = "btnOK";
            this.btnOK.Size = new Size(0x4b, 0x17);
            this.btnOK.TabIndex = 4;
            this.btnOK.Text = "OK";
            this.btnOK.UseVisualStyleBackColor = true;
            this.btnOK.Click += new EventHandler(this.btnOK_Click);
            this.btnCancel.DialogResult = DialogResult.Cancel;
            this.btnCancel.Location = new Point(0x85, 0x6b);
            this.btnCancel.Name = "btnCancel";
            this.btnCancel.Size = new Size(0x4b, 0x17);
            this.btnCancel.TabIndex = 5;
            this.btnCancel.Text = "Cancel";
            this.btnCancel.UseVisualStyleBackColor = true;
            this.lblprefix.AutoSize = true;
            this.lblprefix.Location = new Point(12, 0x4b);
            this.lblprefix.Name = "lblprefix";
            this.lblprefix.Size = new Size(0x21, 13);
            this.lblprefix.TabIndex = 6;
            this.lblprefix.Text = "Prefix";
            this.tbPrefix.Location = new Point(0x66, 0x48);
            this.tbPrefix.Name = "tbPrefix";
            this.tbPrefix.Size = new Size(0x8d, 20);
            this.tbPrefix.TabIndex = 3;
            base.AutoScaleDimensions = new SizeF(6f, 13f);
            base.AutoScaleMode = AutoScaleMode.Font;
            base.ClientSize = new Size(0x105, 0x8a);
            base.Controls.Add(this.tbPrefix);
            base.Controls.Add(this.lblprefix);
            base.Controls.Add(this.btnCancel);
            base.Controls.Add(this.btnOK);
            base.Controls.Add(this.lblIPAddress);
            base.Controls.Add(this.tbIpAddress);
            base.Controls.Add(this.tbToken);
            base.Controls.Add(this.lblToken);
            base.FormBorderStyle = FormBorderStyle.FixedDialog;
            base.Icon = (Icon) manager.GetObject("$this.Icon");
            base.MaximizeBox = false;
            base.Name = "IPInput";
            base.ShowInTaskbar = false;
            base.StartPosition = FormStartPosition.CenterParent;
            this.Text = "Enter IP Address";
            base.ResumeLayout(false);
            base.PerformLayout();
        }

        private void ShowPrompt(string text, string caption)
        {
            MessageBox.Show(text, caption, MessageBoxButtons.OK);
        }

        public string IP
        {
            get
            {
                return this.tbIpAddress.Text;
            }
        }

        public string Prefix
        {
            get
            {
                return this.tbPrefix.Text;
            }
        }

        public string Token
        {
            get
            {
                return this.tbToken.Text;
            }
        }
    }
}

